qui(function(require, exports, module) {
	Sginal.Util = $.extend(true, {}, Ancestor.Util, {
			formatter: {
			    sginalType: function (v, r) {
                    return Sginal.Config.SGINAL_TYPE[v];
                },
                sginalStatus: function (v, r) {
                    return Sginal.Config.SGINAL_STATUS[v];
                },
                serverType: function (v, r) {
                    return Sginal.Config.SERVER_TYPE[v];
                },
                time: function (v, r) {
                    return v.substring(0, 19);
                },
                operate:function(v,r) {
                    var str = "";
                    if (r.status == 0 || r.status == 2) {
                        str += "<a href='/epg/sginal_edit.html?id=" + r.id + "' class='btn btn-info' target='_blank'>修改</a>";
                        str += " <a href='javascript:void(0);' onclick='Sginal.Util.start(" + r.id + ")' class='btn btn-success' style='display:inline' target='_blank'>开启</a>";
                        str += "<a href='javascript:void(0);' onclick='Sginal.Util.stop(" + r.id + ")' class='btn btn-warning' style='display:none' target='_blank'>停止</a>";
                        str += " <a href='javascript:void(0);' onclick='Sginal.Util.del(" + r.id + ")' class='btn btn-danger' target='_blank'>删除</a>";
                    } else {
                        str += "<a href='javascript:void(0)' class='btn btn-info' target='_blank' disabled='disabled'>修改</a>";
                        str += " <a href='javascript:void(0);' onclick='Sginal.Util.start(" + r.id + ")' class='btn btn-success' style='display:none' target='_blank'>开启</a>";
                        str += "<a href='javascript:void(0);' onclick='Sginal.Util.stop(" + r.id + ")' class='btn btn-warning' style='display:inline' target='_blank'>停止</a>";
                        str += " <a href='javascript:void(0);' onclick='Sginal.Util.del(" + r.id + ")' class='btn btn-danger' target='_blank'>删除</a>";
                    }
                    str += " <a href='javascript:void(0);' data-id='" + r.id + "' onclick='Sginal.Util.sginalLogList(this);' class='btn btn-link'>详细</a>";
                    return str;
                }

            },

            del: function(id){
                var self = this;
                // if(window.confirm('是否从列表中删除该数据？')) {
                //     var params = {id : id};
                //     Sginal.Dao.delete(params, function(){
                //         $('.query-btn').click();
                //     });
                //     return true;
                // }

                SystemDialog.queryConfirm("是否从列表中删除该数据？", function (flag) {
                    if (flag == true) {
                        var params = {id : id};
                        Sginal.Dao.delete(params, function(){
                            $('.query-btn').click();
                        });
                    }
                    return true;
                });
            },

            start: function(id){
                var self = this;
                var params = {id : id};
                Sginal.Dao.start(params, function(data){
                    $('.pageClick').click();
                });
                return true;
            },
            stop: function(id){
                var self = this;
                var params = {id : id};
                Sginal.Dao.stop(params, function(data){
                    $('.pageClick').click();
                });
                return true;
            },
            getList: function(pn) {
                $("input[name=pageNo]").val(pn);
                $('.pageClick').click();
            },

            statusList: function(obj) {
                var self = this;
                var id = $(obj).attr('data-id');
                var serverIp = $(obj).attr('data-serverIp');
                var params = {fatherId: id, serverIp: serverIp};

                $('#statusList').jqGrid('setGridParam', {
                    page: 1,
                    datatype: "json",
                    postData: params
                }).trigger('reloadGrid');
                self.openDlg($("#o-h-dlg"), '服务器状态',900 , 600);
            },

            sginalLogList: function(obj) {
                var self = this;
                var fatherId = $(obj).attr('data-id');
                var params = {fatherId: fatherId};

                $('#sginalLogList').jqGrid('setGridParam', {
                    page: 1,
                    datatype: "json",
                    postData: params
                }).trigger('reloadGrid');
                self.openDlg($("#o-h-slog"), '历史记录',900 , 600);
            },

            calculateDate: function (str) {//month 7days yestoday today
                var from_date = "", to_date = "";
                var d = new Date();
                var defaultEnd = this.formatDateTimeFormat(d);
                this.setZeroTime(d);
                if (str == "today") {
                    from_date = this.formatDateTimeFormat(d);
                    to_date = defaultEnd;
                }
                if (str == "yesterday") {
                    d.setDate(d.getDate() - 1);
                    from_date = this.formatDateTimeFormat(d);
                    this.setDayLastTime(d);
                    to_date = this.formatDateTimeFormat(d);
                }

                if (str == "7days") {
                    d.setDate(d.getDate() - 6);
                    from_date = this.formatDateTimeFormat(d);
                    to_date = defaultEnd
                }
                if (str == "month") {
                    d.setMonth(d.getMonth() - 1);
                    from_date = this.formatDateTimeFormat(d);
                    to_date = defaultEnd
                }
                if (str == "absToday") {
                    from_date = this.formatDateTimeFormat(d);
                    this.setDayLastTime(d);
                    to_date = this.formatDateTimeFormat(d);
                }

                if (str == "absToday+") {
                    this.setZeroTime(d);
                    d.setHours(10);
                    from_date = this.formatDateTimeFormat(d);
                    d.setDate(d.getDate() + 1);
                    to_date = this.formatDateTimeFormat(d);
                }

                this.bindDate("startDate", "endDate", { maxDate: to_date, maxDateTime: new Date(to_date.replace(/-/g, "/")), minDate: from_date, minDateTime: new Date(from_date.replace(/-/g, "/"))})
                $("input[name=startDate]").datetimepicker("setDate", new Date(from_date.replace(/-/g, "/")));
                $("input[name=endDate]").datetimepicker("setDate", new Date(to_date.replace(/-/g, "/")));
            },
            formatDateTimeFormat: function (myDate) {
                var year = myDate.getFullYear();
                var month = ("0" + (myDate.getMonth() + 1)).slice(-2);
                var day = ("0" + myDate.getDate()).slice(-2);
                var h = ("0" + myDate.getHours()).slice(-2);
                var m = ("0" + myDate.getMinutes()).slice(-2);
                var s = ("0" + myDate.getSeconds()).slice(-2);
                return year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s;
            },
            setZeroTime: function (checkTime) {
                checkTime.setSeconds(0);
                checkTime.setMinutes(0);
                checkTime.setHours(0);
                checkTime.setMilliseconds(0);
            },
            bindDate: function (nameMin, nameMax, plusData) {
                var options1 = {
                    sliderAccessArgs: { touchonly: false },
                    onClose: function (selectedDate) {
                        console.log("bindDate " +  selectedDate )
                        $("input[name=" + nameMax + "]").datetimepicker("option", "minDate", selectedDate);
                        var toDate = new Date(selectedDate.replace(/-/g, "/"))
                        $("input[name=" + nameMax + "]").datetimepicker("option", "minDateTime", toDate);
                    }
                }
                var options2 = {
                    sliderAccessArgs: { touchonly: false },
                    onClose: function (selectedDate) {
                        console.log("bindDate " +  selectedDate )
                        $("input[name=" + nameMin + "]").datetimepicker("option", "maxDate", selectedDate);
                        var toDate = new Date(selectedDate.replace(/-/g, "/"))
                        $("input[name=" + nameMin + "]").datetimepicker("option", "maxDateTime", toDate);
                    }
                }
                if (plusData != null && plusData.hasOwnProperty("slider")) {
                    options1.controlType = "slider";
                    options2.controlType = "slider";
                }
                $("input[name=" + nameMin + "]").datetimepicker(options1)
                $("input[name=" + nameMax + "]").datetimepicker(options2)
                if (plusData != null) {
                    $("input[name=" + nameMin + "]").datetimepicker("option", "maxDate", plusData.maxDate);
                    $("input[name=" + nameMin + "]").datetimepicker("option", "maxDateTime", plusData.maxDateTime);
                    $("input[name=" + nameMax + "]").datetimepicker("option", "minDate", plusData.minDate);
                    $("input[name=" + nameMax + "]").datetimepicker("option", "minDateTime", plusData.minDateTime);
                }
            },
            setDayLastTime: function (checkTime) {
                checkTime.setSeconds(59);
                checkTime.setMinutes(59);
                checkTime.setHours(23);
                checkTime.setMilliseconds(0);
            },
    });
});